package cn.yunbamboos.rest.service.apidoc.meta;

import cn.hutool.core.util.ObjUtil;
import cn.yunbamboos.rest.service.apidoc.IMeta;
import com.alibaba.fastjson2.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MediaType implements IMeta {

    private Schema schema;
    private JSONObject example;
    private final Map<String, JSONObject> examples = new HashMap<>();

    @Override
    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        json.put("schema", schema.toJSON());
        if(ObjUtil.isNotNull(example)){
            json.put("example", example);
        }
        if(ObjUtil.isNotNull(this.examples) && !this.examples.isEmpty()){
            json.put("examples", this.examples);
        }
        return json;
    }

    public Schema getSchema() {
        return schema;
    }

    public JSONObject getExample() {
        return example;
    }

    public Map<String, JSONObject> getExamples() {
        return examples;
    }

    public void setSchema(Schema schema) {
        this.schema = schema;
    }

    public void setExample(JSONObject example) {
        this.example = example;
    }

    public void putExamples(String key, JSONObject examples) {
        this.examples.put(key, examples);
    }
}
